package com.itheima.dao.impl;

import com.itheima.dao.EmpDao;
import com.itheima.pojo.Emp;
import com.itheima.util.XmlParserUtils;
import org.springframework.stereotype.Component;

import java.util.List;


@Component  /*将实现类交给spring容器管理*/
public class EmpDaoImpl_数据访问层 implements EmpDao {
    @Override
    public List<Emp> listEmp() {
        String file = this.getClass().getClassLoader().getResource("emp.xml").getFile().replaceAll("%20", " ");
//        System.out.println("[" + file + "]");
        //[/F:/IntelijIDEA/IntelliJ%20IDEA%202022.3/IdeaProjects/MyFirstProject/learnSpringBoot/target/classes/emp.xml] 因为路径中有空格,被变成了%20,所以找不到文件emp.xml,通过加上.replaceAll("%20", " ")即可恢复路径不报错
        List<Emp> empList = XmlParserUtils.parse(file, Emp.class);
        return empList;
    }

}
